#!/usr/bin/python
#coding:utf8
'''
Singleton
'''
# 创建一个单态类，该类只能实例化一次
class Singleton:
    '''A python style singleton '''
    def __new__(cls, *args, **kw):
        if not hasattr(cls, '_instance'):
            cls._instance = super().__new__(cls)
        return cls._instance

class SingelA:
    def __new__(cls, *args, **kw):
        if not hasattr(cls, '_instance'):
            cls._instance = super().__new__(cls)
        return cls._instance
    
    def __init__(self, x):
        self.x = x
    
    def __str__(self):
        return self.x

if __name__ == '__main__':
    a1 = SingelA('a')
    a2 = SingelA('b')
    print(a1==a2)

    class B:
        def __init__(self, x):
            self.x = x
    
    class C(B, Singleton):
        def __init__(self, x):
            super().__init__(x)


    c1 = C('c')
    c2 = C('d')
    print(c1.x)